package com.sig.opengl;

import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.sig.LecteurFichier;
import com.sig.core.Tab;
import com.sig.map.Map;
import com.sig.xml.MapXmlParser;

public class OpengGLFragment extends Tab {

	private MyGLSurfaceView _surfaceView = null;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		if(_surfaceView != null){
			Canvas c = new Canvas();
			c.drawColor( Color.BLACK );
			_surfaceView.draw(c);
		}

		_surfaceView = new MyGLSurfaceView(this.getActivity());
		
		charger();
		
		return _surfaceView;
		//_GLView.requestRender();
	}

	@Override
	public void onPause() {
		super.onPause();
		if (_surfaceView != null) { _surfaceView.onPause(); }
	}

	@Override
	public void onResume() {
		super.onResume();
		if (_surfaceView != null) { _surfaceView.onResume(); }
	}

	@Override
	public CharSequence getTitle() {
		return "OpenGL";
	}

	public MyGLSurfaceView getMyGLSurfaceView(){
		return _surfaceView;
	}

	private void charger(){
		String xml = LecteurFichier.readFileFromSDCard("map.xml");
		Log.d("FILE",xml);
		
		MapXmlParser parseur = new  MapXmlParser(xml);
		Map map = parseur.getMap();
		
		_surfaceView.getRenderer().ajouterFormes(map.getFormes());
		Log.d("FORMES",map.getFormes().toString());
	}

}
